package com.sxj.corejava.code14_Lambda表达式;

import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

public class Test03_供给型接口 {

    public static void main(String[] args) {
        // 匿名内部类用法
        List<String> list = testSupplier(new Supplier<List<String>>() {
            @Override
            public List<String> get() {
                return Arrays.asList("admin", "lucy", "jack", "tom");
            }
        });
        System.out.println(list);

        // Lambda表达式用法
        List<String> list2 = testSupplier(() -> Arrays.asList("苍", "东皇太一", "李白", "貂蝉", "吕布"));
        System.out.println(list2);
    }

    /**
     * 供给型接口,无参、有返回值
     * 其泛型的类型与方法的返回值类型一致
     * @param supplier
     * @return
     */
    public static List<String> testSupplier(Supplier<List<String>> supplier) {
        return supplier.get();
    }
}
